package com.mhc.suzuki.service.listener;

import com.alibaba.fastjson.JSON;
import com.mhc.suzuki.event.SnapshotEvent;
import com.mhc.suzuki.service.ModifyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;


@Slf4j
//@Component
/**
 * 快照事件接收
 * Created by kanon on 2017/9/6.
 */
public class SnapshotListener implements ApplicationListener<SnapshotEvent> {

    @Autowired
    private ModifyService modifyService;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void onApplicationEvent(SnapshotEvent snapshotEvent) {
        log.info("接收到了SnapshotEvent:{}", JSON.toJSONString(snapshotEvent));
        modifyService.createModify(snapshotEvent.getEntityType(), snapshotEvent.getBizRecId(), snapshotEvent.getStaffId());
    }
}
